NAMESPACE="qatest"
JOB_NAME="ncsTest"
YAML_FILE="{{ data_dir }}/ncs-qatest/ncs/ncs_scene_job_test.yaml"
CONFIGMAP_TESTXML_FILE="{{ data_dir }}/ncs-qatest/ncs/skiffncs_scenario_test.xml"
CONFIGMAP_TESTXML_NAME="ncs-test-xml"

if [ -d {{ data_dir }}/ncs-qatest/ncs/logs ];then
    mv {{ data_dir }}/ncs-qatest/ncs/logs {{ data_dir }}/ncs-qatest/ncs/logs-`date +%F-%H%M%S`
fi

if [ -d {{ data_dir }}/ncs-qatest/ncs/test-output ];then
    mv {{ data_dir }}/ncs-qatest/ncs/test-output  {{ data_dir }}/ncs-qatest/ncs/test-output-`date +%F-%H%M%S`
fi

if [ ! -n "$(~/kubectl --kubeconfig ~/{{ cluster_name }}/admin.conf get namespaces | grep $NAMESPACE)" ]; then
    ~/kubectl --kubeconfig ~/{{ cluster_name }}/admin.conf create namespace qatest
fi

if [ ! -n "$(~/kubectl --kubeconfig ~/{{ cluster_name }}/admin.conf get configmap -n $NAMESPACE | grep $CONFIGMAP_TESTXML_NAME)" ]; then
	~/kubectl --kubeconfig ~/{{ cluster_name }}/admin.conf create configmap $CONFIGMAP_TESTXML_NAME --from-file=$CONFIGMAP_TESTXML_FILE -n $NAMESPACE
fi


if [ -n "$(~/kubectl --kubeconfig ~/{{ cluster_name }}/admin.conf get job -n $NAMESPACE | grep $JOB_NAME)" ];
 then
    ~/kubectl --kubeconfig ~/{{ cluster_name }}/admin.conf delete job -n $NAMESPACE $JOB_NAME
    ~/kubectl --kubeconfig ~/{{ cluster_name }}/admin.conf apply -f $YAML_FILE
else
    ~/kubectl --kubeconfig ~/{{ cluster_name }}/admin.conf apply -f $YAML_FILE
fi


